package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.VO.SharingVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BuSharing;
import com.ruoyi.business.service.IBuSharingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 绑定分润配置 Controller
 *
 * @author ruoyi
 * @date 2024-09-23
 */
@RestController
@RequestMapping("/business/sharing")
public class BuSharingController extends BaseController
{
    @Autowired
    private IBuSharingService buSharingService;

    /**
     * 查询绑定分润配置 列表
     */
    @PreAuthorize("@ss.hasPermi('business:sharing:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuSharing buSharing)
    {
        startPage();
        List<BuSharing> list = buSharingService.selectBuSharingList(buSharing);
        return getDataTable(list);
    }

    @GetMapping("/lists")
    public AjaxResult lists(BuSharing buSharing)
    {
        List<SharingVO> list = buSharingService.selectBuSharingList2(buSharing);
        return success(list);
    }

    /**
     * 导出绑定分润配置 列表
     */
    @PreAuthorize("@ss.hasPermi('business:sharing:export')")
    @Log(title = "绑定分润配置 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuSharing buSharing)
    {
        List<BuSharing> list = buSharingService.selectBuSharingList(buSharing);
        ExcelUtil<BuSharing> util = new ExcelUtil<BuSharing>(BuSharing.class);
        util.exportExcel(response, list, "绑定分润配置 数据");
    }

    /**
     * 获取绑定分润配置 详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:sharing:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buSharingService.selectBuSharingById(id));
    }

    /**
     * 新增绑定分润配置
     */
    @PreAuthorize("@ss.hasPermi('business:sharing:add')")
    @Log(title = "绑定分润配置 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuSharing buSharing)
    {
        return toAjax(buSharingService.insertBuSharing(buSharing));
    }

    /**
     * 修改绑定分润配置
     */
    @PreAuthorize("@ss.hasPermi('business:sharing:edit')")
    @Log(title = "绑定分润配置 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuSharing buSharing)
    {
        return toAjax(buSharingService.updateBuSharing(buSharing));
    }

    /**
     * 删除绑定分润配置
     */
    @PreAuthorize("@ss.hasPermi('business:sharing:remove')")
    @Log(title = "绑定分润配置 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buSharingService.deleteBuSharingByIds(ids));
    }
}
